#pragma config(Hubs,  S1, HTMotor,  HTServo,  none,     none)
#pragma config(Sensor, S2,     Ben1,                sensorSONAR)
#pragma config(Sensor, S3,     LightSensor,         sensorLightActive)
#pragma config(Motor,  mtr_S1_C1_1,     motorD,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C1_2,     motorE,        tmotorNormal, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
  int mValue = 30;      //Motor power value
  int dValue = 15;      //Motor power value
  int threshold = 50;   //Light sensor threshold value

  while(SensorValue(LightSensor) > threshold)   //while light sensor is seeing "white"
  {
    motor[motorD]= dValue;      //Motor D is run at a 15 power level
    motor[motorE]= dValue;      //Motor E is run at a 15 power level
  }

  motor[motorD]= 0;       //Motor D is run at a 0 power level
  motor[motorE]= 0;       //Motor E is run at a 0 power level
  wait1Msec(500);         //Wait 0.5 seconds

  while(SensorValue(LightSensor) < threshold)   //while light sensor is seeing "black"
  {
    motor[motorD] = mValue;         //Motor D is run at a 30 power level
    motor[motorE] = mValue*(-1);    //Motor E is run at a 30 power level in the reverse direction
  }

  motor[motorD]= 0;       //Motor D is run at a 0 power level
  motor[motorE]= 0;       //Motor E is run at a 0 power level

  while(true)
  {
  	if(SensorValue[LightSensor] < threshold)  // If the Light Sensor reads a value less than 50
  	{
    	  motor[motorD] = mValue;                  // Motor D is run at a 30 power level
    	  motor[motorE] = 0;                  //  Motor E is run at a 0 power level
  	}
  	else                            // If the Light Sensor reads a value greater than or equal to 50
  	{
    	  motor[motorE] = mValue;                  // Motor E is run at a 30 power level
	  motor[motorD] = 0;                  //  Motor D is run at a 0 power level
  	}
  }
}
